package com.lyc.common.config;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lyc.common.interceptor.AuthorInterceptor;

/**
 * 请求拦截器配置
 * @Author 李大神仙
 * @Date 2024/2/26 21:07
 * @Version 1.0
 */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private ObjectMapper objectMapper;

    //@Autowired
    //private UserInterceptor userInterceptor;

    @Autowired
    //private AuthorInterceptor authorInterceptor;

    public static List<String> excludePathPatterns = new ArrayList<>();

    static {
        //在这里可以定义多个排除
        excludePathPatterns.add("/v1/dl/login-auth/**");
        excludePathPatterns.add("/login/**");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       /* //注册拦截器
        registry.addInterceptor(userInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePathPatterns)
                .order(-11);
        registry.addInterceptor(authorInterceptor)
                .excludePathPatterns(excludePathPatterns)
                .addPathPatterns("/**")
                .order(-10);*/
    }

    @PostConstruct
    public void myObjectmapper(){
        //解决enum不匹配问题（空字符串转枚举期异常）默认值为false
        objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL,true);
    }
}
